/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "dal/qos_policy.h"
#include "dal_fastdds/converter/StatusConverter.hpp"
#include <fastdds/dds/core/status/BaseStatus.hpp>
#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
#include <fastdds/dds/core/status/PublicationMatchedStatus.hpp>
#include <fastdds/dds/core/status/DeadlineMissedStatus.hpp>
#include <fastdds/dds/core/status/IncompatibleQosStatus.hpp>
#include <fastdds/dds/core/status/LivelinessChangedStatus.hpp>
#include <fastdds/dds/core/status/SampleRejectedStatus.hpp>

TEST(inconsistent_topic_status_convert, test_convert_status)
{
    InconsistentTopicStatus fstatus;
    dal_inconsistent_topic_status_t hstatus;
    fstatus.total_count = 100l;
    fstatus.total_count_change = 200l;
    StatusConverter::GetInstance()->ConvertInconsistentTopicStatusFromFastddsToDal(&fstatus,
                                                                                   &hstatus);
    EXPECT_EQ(hstatus.total_count, fstatus.total_count);
}

TEST(sample_rejected_status_convert, test_convert_status)
{
    SampleRejectedStatus fstatus;
    dal_sample_rejected_status_t hstatus;
    fstatus.last_reason = REJECTED_BY_INSTANCES_LIMIT;
    StatusConverter::GetInstance()->ConvertSampleRejectedStatusFromFastddsToDal(&fstatus, &hstatus);
    EXPECT_NE(hstatus.last_reason, DAL_REJECTED_BY_SAMPLES_LIMIT);
    EXPECT_EQ(hstatus.last_reason, DAL_REJECTED_BY_INSTANCES_LIMIT);
}

TEST(liveliness_changed_status_convert, test_convert_status)
{
    LivelinessChangedStatus fstatus;
    dal_liveliness_changed_status_t hstatus;
    fstatus.alive_count = 100l;
    fstatus.not_alive_count = 200l;
    fstatus.alive_count_change = 300l;
    fstatus.not_alive_count_change = 400l;
    StatusConverter::GetInstance()->ConvertLivelinessChangedStatusFromFastddsToDal(&fstatus,
                                                                                   &hstatus);
    EXPECT_EQ(hstatus.alive_count, fstatus.alive_count);
    EXPECT_EQ(hstatus.not_alive_count, fstatus.not_alive_count);
    EXPECT_EQ(hstatus.alive_count_change, fstatus.alive_count_change);
    EXPECT_EQ(hstatus.not_alive_count_change, fstatus.not_alive_count_change);
}

TEST(offered_incompatible_qos_status_convert, test_convert_status)
{
    OfferedIncompatibleQosStatus fstatus;
    dal_offered_incompatible_qos_status_t hstatus;
    fstatus.total_count = 100l;
    fstatus.total_count_change = 200l;
    fstatus.last_policy_id = ENTITYFACTORY_QOS_POLICY_ID;
    StatusConverter::GetInstance()->ConvertOfferedIncompatibleQosStatusFromFastddsToDal(&fstatus,
                                                                                        &hstatus);
    EXPECT_EQ(hstatus.total_count, fstatus.total_count);
    EXPECT_EQ(hstatus.total_count_change, fstatus.total_count_change);
    EXPECT_NE(hstatus.last_policy_id, DAL_TIMEBASEDFILTER_QOS_POLICY_ID);
    EXPECT_EQ(hstatus.last_policy_id, DAL_ENTITYFACTORY_QOS_POLICY_ID);
}
